<?php
namespace admin\controllers;

use common\models\Tags;
use Yii;

class TagsController extends BaseController
{
    public $modelClass = 'common\models\Tags';
    public $searchModelClass = 'admin\models\TagsSearch';

    /**
     * 置顶
     */
    public function actionUp()
    {
        $id = Yii::$app->request->get('id');

        $tags = Tags::find();
        foreach ($tags->each() as $tag) {
            if ($tag->id == $id) { //如果是置顶的分类
                $tag->display_order = 255;
            } else {
                $tag->display_order > 0 ?  $tag->display_order -= 1 :  $tag->display_order;
            }
            $tag->save();
        }

        $this->back();
    }
}
